const mongoose = require('mongoose')

mongoose.connect('mongodb://127.0.0.1:27017/data');

mongoose.connection.on('open',()=>{
    //创建数据骨架
    let userSchema = new mongoose.Schema({
        name:{
            type:String,
            default:'yuonly'
        },
        age:{
            type:String,
            default:20
        }
    })

    let userModel = mongoose.model('user',userSchema);

    userModel.insertMany([
        {name:'huhan'},
        {name:'zhangsan',age:18},
        {name:'lisi',age:19},
        {name:'王五',age:21}
    ],(err,data)=>{
        if(err) throw err;
        console.log(data);
    })
})